package com.cabrida.livestar.main;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cabrida.livestar.R;
import com.cabrida.livestar.model.FansGiftData;

/**
 * 兑换L币购买次数adapter
 * 
 * @author why
 * 
 */
public class FansCallStarPayGvAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private ArrayList<FansGiftData> data_list = new ArrayList<FansGiftData>();

	public FansCallStarPayGvAdapter(Context context) {
		this.mInflater = LayoutInflater.from(context);
	}

	public void setData(ArrayList<FansGiftData> data) {
		data_list = data;
	}

	@Override
	public int getCount() {
		return data_list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {

			holder = new ViewHolder();

			convertView = mInflater.inflate(
					R.layout.adapter_callstarconvert_gv_item, null);
			
			holder.tv_num = (TextView) convertView.findViewById(R.id.tv_num);
			holder.tv_money = (TextView) convertView.findViewById(R.id.tv_money);
			holder.ll_all = (LinearLayout) convertView.findViewById(R.id.ll_all);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();

		}
		if (data_list.get(position).isCheck()) {
			holder.ll_all.setBackgroundResource(R.drawable.dialog_callstar_number_press);
		}else {
			holder.ll_all.setBackgroundResource(R.drawable.dialog_callstar_number_normal);
		}
		holder.tv_num.setText(data_list.get(position).getC_sort()+"次");
		holder.tv_money.setText(data_list.get(position).getC_value()+"L币");
		holder.ll_all.setTag(position);
		holder.ll_all.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				int  pos = (Integer) v.getTag();
				for (int i = 0; i < data_list.size(); i++) {
					data_list.get(i).setCheck(false);
					if (pos==i) {
						data_list.get(i).setCheck(true);
					}
				}
				notifyDataSetChanged();
			}
		});
		
		return convertView;
	}

	class ViewHolder {
		private TextView tv_num;
		private TextView tv_money;
		private LinearLayout ll_all;
	}

	
}
